zz_

test/factorial.test.js

zzmq.dev@gmail.com[dev3]/mathkit[add-mean-numbers-function-returns] / test / factorial.test.js @ f501bd86 Download
Ladder Summary
  • file Contains unit tests for the factorial function covering base cases (0 and 1), typical positive integers, and ensuring undefined is returned for negative, non‑integer, NaN, or infinite inputs.
import { test } from "node:test";
import assert from "node:assert/strict";
import { factorial } from "../src/factorial.js";

test("factorial of zero and one", () => {
  assert.strictEqual(factorial(0), 1);
  assert.strictEqual(factorial(1), 1);
});

test("factorial of positive integers", () => {
  assert.strictEqual(factorial(5), 120);
  assert.strictEqual(factorial(10), 3628800);
});

test("factorial returns undefined for invalid inputs", () => {
  assert.strictEqual(factorial(-1), undefined);
  assert.strictEqual(factorial(2.5), undefined);
  assert.strictEqual(factorial(NaN), undefined);
  assert.strictEqual(factorial(Infinity), undefined);
});